<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/2
 * Time: 11:27
 */

namespace app\admin\controller;


use think\Db;
use \think\Cookie;

class Integral extends User
{
    public function index(){
        $info=Db::name('integral')->select();
        foreach ($info as $k=>$v){
            $admin=Db::name('admin')->where(['id'=>$v['operator']])->find();
            $info[$k]['admin']=$admin['nickname'];
        }
        $this->assign('info', $info);
        return $this->fetch();
    }
    public function edit(){
        //获取管理员id

        if ($this->request->isPost()){
            $adminid = Cookie::get('admin');
            $params=$this->request->param();
            $params['updatetime']=time();
            $params['operator']=$adminid;
            $data=Db::name('integral')->where(['integral_id'=>$params['integral_id']])->update($params);
            if (!$data){
                return $this->error('修改失败','','0');
            }
            return  $this->success('修改成功','','1');
        }
        $ids=$this->request->param('uid');
        $info=Db::name('integral')->where(['integral_id'=>$ids])->find();
        $this->assign('info',$info);
        return $this->fetch();
    }
}